Post

Replies

Boosts

Views

Activity

Reply to URLSession with background configuration doesn't works
Thanks for Your reply. I understand that URLSession in view controller is bad idea. Usually I implement singleton and provide all session information by NotificationCenter without delegates. But by given code example I want to in easy way show my problem. In my real project application should download file near 300MB size, not 2MB images. For that right i should use background mode and notifications, to give user possibility dismiss view controller which initiate loading process (application in foreground) and send application to background (go to home screen, launch another app, screen lock).Your code examplelet nsm = NetworkSessionManager(delegate: self)use default session configurationlet config = URLSessionConfiguration.defaultand in this case everything works fine except continue of downloading when application moved to background. In this case I receive error message "The operation couldn't be completed. Software caused connection abort".Also, using Your code example, I changed default session manager initialization in view controllerlet nsm = NetworkSessionManager(delegate: self)to init(withBackgroundSession:)let nsm = NetworkSessionManager(withBackgroundSession: "com.example.my.session", delegate: self)which use background URLSessionConfiguration.let config = URLSessionConfiguration.background(withIdentifier: withBackgroundSession)Now, with background configuration downloading is resumed in background and i see response in text view. But I do next steps, after which problem occurs:Terminate application in app switcherDisconnect iPhone from MacLaunch application on iPhone - (app all time in foreground) usually in second I receive message "The operation couldn't be completed. No such file or directory."Restart iPhoneLaunch application on iPhone - (app all time in foreground) nothing not happened. Text view doesn't changed, response never been received. Reason - request wasn't sent. I know it because I can see all requests in our local network using special proxy.Just try repeat those steps. Hope this explanation will be more useful and help to solve this problem.
Dec ’19